package com.mdp.im.core.publish.action.impl;

import com.alibaba.fastjson.JSONObject;
import com.mdp.im.core.entity.ImGroupMessage;
import com.mdp.im.core.entity.ImPrichatMessage;
import com.mdp.im.core.publish.action.AbstractPublishAction;
import com.mdp.im.core.publish.api.action.PublishAction;
import com.mdp.im.core.publish.api.Publisher;
import com.mdp.im.core.service.ImGroupMessageService;
import com.mdp.im.core.service.ImGroupService;
import com.mdp.im.core.service.ImGroupUserService;
import com.mdp.im.core.service.ImPrichatMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 删除消息处理器
 * 
 * @author chenyc
 * @date 2018/6/5
 */
@Service("pushRemoveMessageAction")
public class RemoveMessageAction extends AbstractPublishAction implements PublishAction {

	@Autowired
	ImGroupService groupService;
	@Autowired
	ImGroupUserService groupUserService;
	
	@Autowired
	ImGroupMessageService groupMessageService;
	
	@Autowired
	ImPrichatMessageService prichatMessageService;
	
	@Autowired
	Publisher publisher;
    /**
     * 删除消息
     */
    @Override
    public void doAction(JSONObject message) {
        JSONObject json = message;
        String sourceMsgId=json.getString("sourceMsgId");
        String msgType=json.getString("msgType");
        String groupId=json.getString("groupId");
        if("group".equals(msgType)) {
        	 ImGroupMessage m=new ImGroupMessage();
        	 m.setMsgId(sourceMsgId);
        	 groupMessageService.deleteByPk(m);
        	 String msg=message.toJSONString();
        	 publisher.publishGroupMessage(groupId, msg); 
        	 //publisher.publishGroupMessageToDbQueue(msg);
        }else if("prichat".equals(msgType)){
        	 ImPrichatMessage m=new ImPrichatMessage();
        	 m.setMsgId(sourceMsgId);
        	 prichatMessageService.deleteByPk(m);
        	 String msg=message.toJSONString();
        	 publisher.publishPrichatMessage(message.getString("toUserid"),msg);
        }
       
        
        
    }

}
